home *** CD-ROM | disk | FTP | other *** search
- Path: news.sprintlink.net!datalytics!news
- From: Rob Stewart <stew@datalytics.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Binary IOStreams?
- Date: 8 Jan 1996 18:59:49 GMT
- Organization: Datalytics, Inc
- Message-ID: <4crpj5$h4r@gold.datalytics.com>
- References: <DKny36.A0@BearRiver.com>
- NNTP-Posting-Host: pc071.datalytics.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
-
- Duane Murphy <dmurphy@bearriver.com> wrote:
- >Are IOStreams (the ios & streambuf hieararchy) always text streams?
- >Is there a way to make the become binary? Is there a seperate
- >specification or hierarchy for binary streams?
- >
-
- There is no version of the iostreams classes to handle
- strictly binary I/O of the data.
-
- >By binary streams I mean streams where operator>>(int) does _NOT_
- >first convert to the text of the number but just emits its binary
- >representation (ie by calling streambuf::write()).
- >
-
- You can effect this behavior pretty easily. However, you must
- override all of the shift operators for each of the types.
- You can use ostream::write() and istream::read() to handle the
- binary data.
-
- Thus, this should do the trick.
-
- class bistream : public istream
- {
- public:
- ...
- inline
- istream& operator >>(
- int& o_Number);
- ...
- };
-
- inline
- istream& istream::operator >>(
- int& o_Number)
- {
- read(
- (char*)&o_Number,
- sizeof(o_Number));
- return *this;
- }
-
- class bostream : public ostream
- {
- public:
- ...
- inline
- ostream& operator <<(
- int i_Number);
- ...
- };
-
- inline
- ostream& ostream::operator <<(
- int& i_Number)
- {
- write(
- (char*)&i_Number,
- sizeof(i_Number));
- return *this;
- }
-
- --
- Robert Stewart | My opinions are usually my own.
- Datalytics, Inc.
- (513)226-7700
- stew@datalytics.com
-
-
-